﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Presentation.Web.Core.CDN;

namespace Presentation.Web.UI.Extensions
{
    public static class CDNExtensions
    {
        public static string CDNContent(this UrlHelper urlHelper, string relativeUrl)
        {
            if (relativeUrl[0] != '~')
            {
                throw new ArgumentException("cdn url must start with \"~\"", "relativeUrl");
            }
            string cdnPath = "";//SchoolContextManager.Current.MediaServer;
            string clientUrl = urlHelper.Content(Cachable(relativeUrl));
            return !String.IsNullOrEmpty(cdnPath) ?
                new Uri(new Uri(cdnPath), clientUrl).OriginalString : clientUrl;
        }
        private static string Cachable(string relativeUrl)
        {
            return UrlProvider.Instance.GetCachableVirtualPath(relativeUrl);
        }
    }
}
